import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:laos_mall/common/style/extension_util.dart';

enum ToastType { none,loading, success, error }

void showToast(String message,{BuildContext? context,ToastType type = ToastType.none, int? value}) {
  SmartDialog.showToast(
    '',
    builder: (context) {
      return Container(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 5),
        decoration: const BoxDecoration(
          color: Colors.black, // Toast 背景颜色
          borderRadius: BorderRadius.zero, // 设置圆角为 0
        ),
        constraints: BoxConstraints(maxWidth: 340),
        child: Row(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (type == ToastType.loading)
              const SizedBox(
                width: 24,
                height: 24,
                child: CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
                  strokeWidth: 2,
                ),
              ),
            if (type == ToastType.success)
              Image.asset('ic_sucess'.toImgPath(),width: 14.w,height: 14.w,),
            if (type == ToastType.error)
              Image.asset('ic_error'.toImgPath(),width: 14.w,height: 14.w,),
            const SizedBox(width: 10),
            Text(
              message,
              style: const TextStyle(color: Colors.white, fontSize: 16),
              textAlign: TextAlign.center,
            ).addContainer(constraints: BoxConstraints(maxWidth: 280),color: Colors.transparent),
          ],
        ),
      );
    },
    alignment: Alignment.center, // Toast 显示位置
    displayTime: const Duration(seconds: 2), // 显示时长
  );
}

void showLoading({String msg = 'loading...'}){
  SmartDialog.showLoading(msg: msg);
}

void dismiss(){
  SmartDialog.dismiss();
}